<?

require_once './application/core/CoreBase.php';
require_once './application/core/Sonde/indexCore.php';
require_once './application/core/Sonde/readConf.php';
require_once './application/core/Client/sondeSoap.php';
require_once './application/models/Tables/cache.php';
require_once './library/XML/xmlToObjArray.php';

class confCore extends IndexCore
{

    private $_param;
    private $_c;
    private $_once;

    public function readConf()
    {
        $this->_param = array('action' => 'read');
        $this->_c = new sondeSoap($this->_controller);
        $this->_c->read($this->_param, 'sondereadresp');
        $this->MiseEnAttenteReponse(true, '/sonde/readresp', null);
    }

    public function readRespConf()
    {
        $cache = new cache();
        $rst = $cache->getInfo($this->_controller->_idClient, "sondereadresp");
        if ($rst != false)
        {
            for ($i = 0, $n = count($rst); $i < $n; $i++)
            {
                $cache->deleteInfo($this->_controller->_idClient, 'sondereadresp', $rst[$i]['Id']);
                if ($i == $n - 1)
                {
                    $this->_obj = $this->parseReadResp($rst[$i]['Xml']);
                    $this->MiseEnAttenteReponse(false, '/sonde/readresp', $this->_obj);
                }
            }
            return true;
        } else
            $this->MiseEnAttenteReponse(true, '/sonde/readresp', null);
    }

    private function parseReadResp($xml)
    {
        $this->_obj = new CoreBase($this->_controller);
        $this->_xml = $this->_obj->parseResp($xml);
        $this->_xml = base64_decode($this->_xml['CONFIGURATION'][0]['DATA'][0][0]);
        $this->_obj = new readConf($this->_controller);
        $this->_xml = $this->_obj->readConfXML($this->_xml);
        return $this->_xml;
    }

}